package wifiunion.com.notice;

import java.util.HashMap;

/**
 * Created by Administrator on 2017/5/25.
 */

public class DataSyncPresenter implements DataSyncContact.Presenter, DataSyncContact.Callback {

    /**
     * 0 获取数据同步任务列表
     * 1 获取数据同步分组列表
     * 2 删除数据同步任务
     * 3 复制数据同步任务
     * 4 删除数据同步任务分组
     * <p>
     * 5 获取分组列表
     * 6 添加分组
     * 7 添加分组成员
     * 8 立即同步
     * 9 获取数据同步记录列表
     * 10 获取同步任务的同步记录数量
     */
    private int mType = 0;

    DataSyncModel dataSyncModel;

    private BaseView mView;

    //    DataSyncContact.View
    public DataSyncPresenter(BaseView view, int type) {
        mType = type;
        mView = view;
        dataSyncModel = new DataSyncModel();
    }


    @Override
    public void onSuccess(Object data) {

        switch (mType) {
            case 0:
                ((DataSyncContact.View) mView).onSuccess(data);
                break;
            case 1:
                ((DataSyncContact.View) mView).getGroupListSuccess(data);
                break;
            case 2:
                ((DataSyncContact.View) mView).delDatasyncSuccess(data);
                break;
            case 3:
                ((DataSyncContact.View) mView).copyDatasyncSuccess(data);
                break;
            case 4:
                ((DataSyncContact.View) mView).delGroupSuccess(data);
                break;
            /*case 5:
                mView.getGroupListSuccess(data);
                break;*/
            case 6:
                ((DataSyncContact.View) mView).addGroupSuccess(data);
                break;
            case 7:
                ((DataSyncContact.View) mView).addGroupMemberSuccess(data);
                break;
            case 8:
                ((DataSyncContact.View) mView).datasyncRightnowSuccess(data);
                break;
            case 9:
                ((DataSyncContact.RecordView) mView).onSuccess(data);
                break;
            case 10 :
                ((DataSyncContact.RecordView) mView).getRecordCountSuccess(data);
                break;

        }
    }

    @Override
    public void onServerFailed(Object errorObj) {
        switch (mType) {
            case 0:
                ((DataSyncContact.View) mView).onError(errorObj);
                break;
            case 1:
                ((DataSyncContact.View) mView).getGroupListFailed(errorObj);
                break;
            case 2:
                ((DataSyncContact.View) mView).delDatasyncFailed(errorObj);
                break;
            case 3:
                ((DataSyncContact.View) mView).copyDatasyncFailed(errorObj);
                break;
            case 4:
                ((DataSyncContact.View) mView).delGroupFailed(errorObj);
                break;
            /*case 5:
                mView.getGroupListFailed(errorObj);
                break;*/
            case 6:
                ((DataSyncContact.View) mView).addGroupFailed(errorObj);
                break;
            case 7:
                ((DataSyncContact.View) mView).addGroupMemberFailed(errorObj);
                break;
            case 8:
                ((DataSyncContact.View) mView).datasyncRightnowFailed(errorObj);
                break;
            case 9:
                ((DataSyncContact.RecordView) mView).onError(errorObj);
                break;
            case 10 :
                ((DataSyncContact.RecordView) mView).getRecordCountFailed(errorObj);
                break;
        }
    }

    @Override
    public void onNetFailed() {
        switch (mType) {
            case 0:
                ((DataSyncContact.View) mView).onError("网络异常");
                break;
            case 1:
                ((DataSyncContact.View) mView).getGroupListFailed("网络异常");
                break;
            case 2:
                ((DataSyncContact.View) mView).delDatasyncFailed("网络异常");
                break;
            case 3:
                ((DataSyncContact.View) mView).copyDatasyncFailed("网络异常");
                break;
            case 4:
                ((DataSyncContact.View) mView).delGroupFailed("网络异常");
                break;
            /*case 5:
                mView.getGroupListFailed("网络异常");
                break;*/
            case 6:
                ((DataSyncContact.View) mView).addGroupFailed("网络异常");
                break;
            case 7:
                ((DataSyncContact.View) mView).addGroupMemberFailed("网络异常");
                break;
            case 8:
                ((DataSyncContact.View) mView).datasyncRightnowFailed("网络异常");
                break;
            case 9:
                ((DataSyncContact.RecordView) mView).onError("网络异常");
                break;
            case 10 :
                ((DataSyncContact.RecordView) mView).getRecordCountFailed("网络异常");
                break;
        }
    }

    @Override
    public void start() {

    }

    @Override
    public void start(HashMap<String, Object> param1s) {

    }


    public void getDatasynclist(HashMap<String, Object> param1s) {
        ((DataSyncContact.View) mView).onProgress();
        dataSyncModel.getDatasynclistRequest(param1s, this);
    }

    public void getDatasyncgroup(HashMap<String, Object> param1s) {
        ((DataSyncContact.View) mView).onProgress();
        dataSyncModel.getDatasyncgroupRequest(param1s, this);
    }


    public void getDatasyncRecord(HashMap<String, Object> param1s) {
        ((DataSyncContact.RecordView) mView).onProgress();
        dataSyncModel.getDatasyncRecordRequest(param1s, this);
    }

    public void delDatasync(HashMap<String, Object> param1s) {
        ((DataSyncContact.View) mView).onProgress();
        dataSyncModel.delDatasyncRequest(param1s, this);
    }

    public void copyDatasync(HashMap<String, Object> params) {
        ((DataSyncContact.View) mView).onProgress();
        dataSyncModel.copyDatasyncRequest(params, this);
    }

    /**
     * 添加分组
     *
     * @param params
     */
    public void addDatasyncGroup(HashMap<String, Object> params) {
        dataSyncModel.addDatasyncGroupRequest(params, this);
    }

    /**
     * 获取分组列表
     *
     * @param params
     */
    public void getDatasyncGrouplist(HashMap<String, Object> params) {
        dataSyncModel.getDatasyncGrouplistRequest(params, this);
    }

    /**
     * 删除分组
     *
     * @param params
     */
    public void delDatasyncGroup(HashMap<String, Object> params) {
        dataSyncModel.delDatasyncGroupRequest(params, this);
    }

    /**
     * 添加分组成员
     *
     * @param params
     */
    public void addDatasyncGroupMember(HashMap<String, Object> params) {
        dataSyncModel.addDatasyncGroupMemberRequest(params, this);
    }


    /**
     * 立即同步
     *
     * @param params
     */
    public void datasyncRightNow(HashMap<String, Object> params) {
        ((DataSyncContact.View) mView).onProgress();
        dataSyncModel.datasyncRightNowRequest(params, this);
    }

    /**
     * 数据同步列表
     * @param params
     */
    public void getDatasyncRecordCount(HashMap<String, Object> params) {
        ((DataSyncContact.RecordView) mView).onProgress();
        dataSyncModel.getDatasyncRecordCountRequest(params, this);
    }
}
